package com.csnf.servlet;

import com.csnf.dao.IClazzDao;
import com.csnf.dao.impl.ClazzDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet({"/getAllClazz","/getAllClazzToList","/getClazzById"})
public class ClazzServlet extends HttpServlet {
    IClazzDao clazzDao = new ClazzDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        String servletPath = req.getServletPath();
        switch (servletPath){
            case "/getAllClazz":
                //查询所有班级,必将班级信息保存到request域中，让页面可以获取
                req.setAttribute("clazzList",clazzDao.findAll());
                req.getRequestDispatcher("addStudent.jsp").forward(req,resp);
                break;
            case "/getAllClazzToList":
                //查询所有班级,必将班级信息保存到request域中，让页面可以获取
                req.setAttribute("clazzList",clazzDao.findAll());
                req.setAttribute("clazzListName","班级列表");
                req.getRequestDispatcher("clazzList.jsp").forward(req,resp);
                break;
            case "/getClazzById":
                String cId = req.getParameter("cId");
                //查询所有班级,必将班级信息保存到request域中，让页面可以获取
                req.setAttribute("clazz",clazzDao.findById(Integer.parseInt(cId)));
                req.getRequestDispatcher("clazzOfStudent.jsp").forward(req,resp);
                break;
        }
    }
}
